import axios from 'axios';
// import qs from "qs" qs.stringify(data))
import {
    APIROOT,
    FILEROOT,
    LoginGetTokenResource,
    LoginGenerateEmailCodeResource,
    LoginRegisterUserResource,
    LoginForgetPasswordResource,
    MainPageControllerQueryCoSpiderInfoListResource,
    ShellControllerSearchComicResource,
    MainPageControllerQueryCoSpiderInfoByIdResource,
    MainPageControllerQueryHistoryRecordPageResource,
    MainPageControllerCoCollectInfoPageByUserResource,
    ShellControllerDetailComicResource,
    OperationControllerSaveCollectComicResource,
    MainPageControllerQueryCollectComicPageResource,
    ShellControllerPictureComicPageResource,
    MainPageControllerQueryRotationPictureResource,
    MainPageControllerQueryHomepageInfoResource,
    MainPageControllerQueryDefaultSpiderInfoResource,
    UserGetDataResource,
    UserSaveOrUpdateResource,
    MinioControllerUploadResource,
    MainPageControllerCoCollectInfoListByUserResource,
    OperationControllerCancelCollectComicResource,
    OperationControllerSaveHistoryRecordResource,
    OperationControllerDeleteHistoryRecordResource,
    UserFindListPageResource,
    UserDeleteByIdsResource,
    MainPageControllerQueryRotationPicturePageResource,
    OperationControllerAddAndEditRotationPictureResource,
    OperationControllerDeleteOtherPicturePictureResource,
    OperationControllerAddAndEditCollectComicResource,
    PyControllerQueryCollectComicPageResource,
    PyControllerAddAndEditSpiderInfoByUserResource,
    OperationControllerDeleteCoSpiderInfoResource,
    PyControllerQueryPyFileAllResource,
    PyControllerApplyUserUploadPyFileResource,
} from './resource';
import {
    AxiosInterceptors
} from '@/config/interceptor/responseInterceptor'
import {
    AxiosRequestInterceptors
} from '@/config/interceptor/requestInterceptor'
AxiosInterceptors
AxiosRequestInterceptors

export default {
    //api根路径
    APIROOT,
    //文件获取根路径
    FILEROOT,
    /** 
     * 登录界面
     */
    //登录获取信息
    getLoginGetToken(data) {
        return axios.post(LoginGetTokenResource, data)
    },
    //获取验证码
    getLoginGenerateEmailCode(email) {
        return axios.get(LoginGenerateEmailCodeResource, {
            params: {
                email: email
            }
        })
    },
    //注册
    getLoginRegisterUserResource(data) {
        return axios.post(LoginRegisterUserResource, data)
    },
    //忘记密码
    getLoginForgetPasswordResource(data) {
        return axios.post(LoginForgetPasswordResource, data)
    },
    //获取Python文件信息
    getMainPageControllerQueryCoSpiderInfoListResource(keyword, userId) {
        return axios.get(MainPageControllerQueryCoSpiderInfoListResource, {
            params: {
                keyword: keyword || null,
                userId: userId || null
            }
        })
    },
    //搜索漫画
    getShellControllerSearchComicResource(pyId, keyword, pageIndex) {
        return axios.get(ShellControllerSearchComicResource, {
            params: {
                pyId: pyId || null,
                pageIndex: pageIndex || null,
                keyword: keyword || null
            }
        })
    },
    //根据id获取py文件
    getMainPageControllerQueryCoSpiderInfoByIdResource(pyId) {
        return axios.get(MainPageControllerQueryCoSpiderInfoByIdResource, {
            params: {
                id: pyId || null,
            }
        })
    },
    //获取用户历史记录
    getMainPageControllerQueryHistoryRecordPageResource(pageIndex, pageSize, userId) {
        return axios.get(MainPageControllerQueryHistoryRecordPageResource, {
            params: {
                pageIndex: pageIndex || 1,
                pageSize: pageSize || 10,
                userId: userId
            }
        })
    },
    //获取用户收藏漫画
    getMainPageControllerCoCollectInfoPageByUserResource(pageIndex, pageSize, userId) {
        return axios.get(MainPageControllerCoCollectInfoPageByUserResource, {
            params: {
                pageIndex: pageIndex || 1,
                pageSize: pageSize || 10,
                userId: userId
            }
        })
    },
    //获取漫画详情
    getShellControllerDetailComicResourceResource(pageIndex, pyId, url) {
        return axios.get(ShellControllerDetailComicResource, {
            params: {
                pageIndex: pageIndex,
                pyId: pyId,
                url: url
            }
        })
    },
    //收藏漫画
    getOperationControllerSaveCollectComicResource(data){
        return axios.post(OperationControllerSaveCollectComicResource, data)
    },
    //推荐漫画
    getMainPageControllerQueryCollectComicPageResource(pageIndex, pageSize,keyword) {
        return axios.get(MainPageControllerQueryCollectComicPageResource, {
          params: {
            pageIndex: pageIndex || 1,
            pageSize: pageSize || 10,
            keyword: keyword || '',
          }
        })
    },
    //获取阅读界面信息
    getShellControllerPictureComicPageResource(pyId,url) {
        return axios.get(ShellControllerPictureComicPageResource, {
          params: {
            pyId: pyId,
            url: url,
          }
        })
    },
    //获取轮播图
    getMainPageControllerQueryRotationPictureResource(){
        return axios.get(MainPageControllerQueryRotationPictureResource)
    },
    //获取最新漫画信息 0-最新漫画
    getMainPageControllerQueryHomepageInfoResource(pageIndex,pageSize,spiderId,type) {
        return axios.get(MainPageControllerQueryHomepageInfoResource,{
            params: {
                pageIndex: pageIndex,
                pageSize: pageSize,
                spiderId: spiderId,
                type: type
            }
        })
    },
    //获取主页默认源
    getMainPageControllerQueryDefaultSpiderInfoResource(){
        return axios.get(MainPageControllerQueryDefaultSpiderInfoResource)
    },
    //获取用户信息
    getUserGetDataResource(userId) {
        return axios.get(UserGetDataResource, {
          params: {
            id: userId
          }
        })
    },
    //修改用户信息
    getUserSaveOrUpdateResource(data) {
        return axios.post(UserSaveOrUpdateResource, data)
    },
    //文件上传
    getMinioControllerUploadResource(data) {
        // console.log(file.file)
        // console.log(file.file.name)
        // 创建FormData对象
        let param = new FormData()
        // 将得到的文件流添加到FormData对象
        // param.append('file', file, file.name)
        param.append('file', data.file)
        param.append('fileName', data.file.name)
        let config = {
            headers: {
                'Content-Type': 'multipart/form-data'
            }
        }; 
        //添加请求头
        return axios.post(MinioControllerUploadResource, param, config);
    },
    //获取用户收藏漫画,不分页
    getMainPageControllerCoCollectInfoListByUserResource(userId) {
        return axios.get(MainPageControllerCoCollectInfoListByUserResource, {
          params: {
            userId: userId
          }
        })
    },
    //取消收藏漫画
    getOperationControllerCancelCollectComicResource(ids) {
        return axios.get(OperationControllerCancelCollectComicResource, {
          params: {
            ids: ids
          }
        })
    },
    //增加历史记录
    getOperationControllerSaveHistoryRecordResource(data) {
        return axios.post(OperationControllerSaveHistoryRecordResource, data)
    },
    //删除历史记录
    getOperationControllerDeleteHistoryRecordResource(ids) {
      return axios.get(OperationControllerDeleteHistoryRecordResource, {
        params: {
          ids: ids
        }
      })
    },
    //获取用户列表
    getUserFindListPageResource(pageIndex, pageSize, keyword) {
        return axios.get(UserFindListPageResource, {
            params: {
                pageIndex: pageIndex,
                pageSize: pageSize,
                keyword: keyword
            }
        })
    },
    //删除用户
    getUserDeleteByIdsResource(ids){
        return axios.get(UserDeleteByIdsResource, {
        params: {
            ids: ids
        }
        })
    },
    //获取轮播图,分页
    getMainPageControllerQueryRotationPicturePageResource(pageIndex, pageSize, keyword) {
        return axios.get(MainPageControllerQueryRotationPicturePageResource, {
          params: {
            pageIndex: pageIndex,
            pageSize: pageSize,
            keyword: keyword || '',
          }
        })
    },
    //新增修改轮播图
    getOperationControllerAddAndEditRotationPictureResource(data){
        return axios.post(OperationControllerAddAndEditRotationPictureResource, data)
    },
    //删漫画或轮播图
    getOperationControllerDeleteOtherPicturePictureResource(ids){
        return axios.get(OperationControllerDeleteOtherPicturePictureResource, {
        params: {
            ids: ids
        }
        })
    },
    //新增修改推荐漫画
    getOperationControllerAddAndEditCollectComicResource(data) {
        return axios.post(OperationControllerAddAndEditCollectComicResource, data)
    },
    //获取用户上传的py文件信息
    getPyControllerQueryCollectComicPageResource(pageIndex, pageSize, userId) {
        return axios.get(PyControllerQueryCollectComicPageResource, {
        params: {
            pageIndex: pageIndex,
            pageSize: pageSize,
            id: userId,
        }
        })
    },
    //新增修改python文件 用户
    getPyControllerAddAndEditSpiderInfoByUserResource(data) {
        return axios.post(PyControllerAddAndEditSpiderInfoByUserResource, data)
    },
    //删除python文件 
    getOperationControllerDeleteCoSpiderInfoResource(ids) {
        return axios.get(OperationControllerDeleteCoSpiderInfoResource, {
          params: {
            ids: ids
          }
        })
    },
    //获取python文件
    getPyControllerQueryPyFileAllResource(pageIndex, pageSize, keyword, state) {
        return axios.get(PyControllerQueryPyFileAllResource, {
          params: {
            pageIndex: pageIndex,
            pageSize: pageSize,
            keyword: keyword,
            state: state,
          }
        })
    },
    //审核漫画
    getPyControllerApplyUserUploadPyFileResource(data){
        return axios.post(PyControllerApplyUserUploadPyFileResource, data)
    }

};